package org.jsola.hr.helper;

import org.jsola.hr.dto.NewsTypeAddDTO;
import org.jsola.hr.dto.NewsTypeUpdateDTO;
import org.jsola.hr.entity.NewsTypeDO;
import org.jsola.hr.query.NewsTypeQuery;
import org.jsola.hr.service.INewsTypeService;
import org.jsola.hr.vo.NewsTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 官网信息的类型
 *
 * @author zhr
 */
@Component
public class NewsTypeTestHelper extends BaseTestHelper {
    
    @Autowired
    private INewsTypeService newsTypeService;

    /**
     * 生成add测试数据
     * @return NewsTypeAddDTO
     */
    public NewsTypeAddDTO getNewsTypeAddDTO(){
        NewsTypeAddDTO newsTypeAddDTO = new NewsTypeAddDTO();
        newsTypeAddDTO.setNewsGroupId(getRandomValue("varchar",32));
        newsTypeAddDTO.setCode(getRandomValue("varchar",50));
        newsTypeAddDTO.setName(getRandomValue("text",2147483647));
        return newsTypeAddDTO;
    }


    /**
     * 生成update测试数据
     * @return NewsTypeUpdateDTO
     */
    public NewsTypeUpdateDTO getNewsTypeUpdateDTO(NewsTypeVO newsTypeVO){
        return newsTypeService.selectDOById(newsTypeVO.getId(), SITE_ID).to(NewsTypeUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return NewsTypeQuery
     */
    public NewsTypeQuery getNewsTypeQuery() {
        NewsTypeQuery newsTypeQuery = new NewsTypeQuery();
        List<NewsTypeDO> newsTypeDOList = newsTypeService.list(new NewsTypeDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(newsTypeDOList)) {
            NewsTypeDO newsTypeDO = newsTypeDOList.get(0);
            newsTypeQuery = newsTypeDO.to(NewsTypeQuery.class);
        }
        return newsTypeQuery;
    }

    /**
     * 保存示例
     * @return NewsTypeVO
     */
    public NewsTypeVO saveNewsTypeExample(){
        NewsTypeAddDTO addDTO = this.getNewsTypeAddDTO();
        NewsTypeVO newsTypeVO = newsTypeService.save(addDTO,buildTokenUser());
        return newsTypeVO;
    }


}

